#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>

void ShellSort(int* a, int n)
{
	int gap = n;
	while (gap > 1)
	{
		gap = gap / 2;
		for (int i = 0; i < n - gap; i++)
		{

			int end = i;
			int tmp = a[i + gap];
			while (end >= 0)
			{
				if (a[end] > tmp)
				{
					a[end + gap] = a[end];
					end -= gap;
				}
				else
				{
					break;
				}
			}
			a[end + gap] = tmp;
		}
	}
}

void InsertSort(int* a,int n)
{	
	for (int i = 1; i < n; i++)
	{
		int end = i-1;
		int tmp = a[i];
		while (end >= 0)
		{
			if (a[end] > tmp)
			{
				a[end+1] =a[end] ;
				end--;
			}
			else
			{
				break;
			}
		}
		a[end+1] = tmp;
	}
}

int main()
{
	int arr[] = {43, 2,7,3,6,4,5,9,1 };
	int size = sizeof(arr) / sizeof(arr[0]);
	//Print();
	//InsertSort(arr, size);
	ShellSort(arr, size);
	int i = 0;
	for (i = 0; i < size; i++)
	{
		printf("%d ", arr[i]);
	}
	
	//Print();
	return 0;
}